package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.CollectionTask;
import com.ruoyi.system.mapper.CollectionTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TaskExecutionRecordMapper;
import com.ruoyi.system.domain.TaskExecutionRecord;
import com.ruoyi.system.service.ITaskExecutionRecordService;
import com.ruoyi.common.core.text.Convert;

/**
 * 采集任务执行记录信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-30
 */
@Service
public class TaskExecutionRecordServiceImpl implements ITaskExecutionRecordService
{
    @Autowired
    private TaskExecutionRecordMapper taskExecutionRecordMapper;
    @Autowired
    private CollectionTaskMapper collectionTaskMapper;

    /**
     * 查询采集任务执行记录信息
     *
     * @param recordId 采集任务执行记录信息主键
     * @return 采集任务执行记录信息
     */
    @Override
    public TaskExecutionRecord selectTaskExecutionRecordByRecordId(Long recordId)
    {
        return taskExecutionRecordMapper.selectTaskExecutionRecordByRecordId(recordId);
    }

    /**
     * 查询采集任务执行记录信息列表
     *
     * @param taskExecutionRecord 采集任务执行记录信息
     * @return 采集任务执行记录信息
     */
    @Override
    public List<TaskExecutionRecord> selectTaskExecutionRecordList(TaskExecutionRecord taskExecutionRecord)
    {
        List<TaskExecutionRecord> taskExecutionRecords = taskExecutionRecordMapper.selectTaskExecutionRecordList(taskExecutionRecord);
        taskExecutionRecords.forEach(item -> {
           //获取任务ID
            Long taskId = item.getTaskId();
            if(taskId != null){
                //根据任务ID查询任务名称
                CollectionTask collectionTask1 = collectionTaskMapper.selectCollectionTaskById(taskId);
                if(collectionTask1 != null) {
                    item.setTaskName(collectionTask1.getTaskName());
                }
            }
        });
        return taskExecutionRecords;
    }

    /**
     * 新增采集任务执行记录信息
     *
     * @param taskExecutionRecord 采集任务执行记录信息
     * @return 结果
     */
    @Override
    public int insertTaskExecutionRecord(TaskExecutionRecord taskExecutionRecord)
    {
        return taskExecutionRecordMapper.insertTaskExecutionRecord(taskExecutionRecord);
    }

    /**
     * 修改采集任务执行记录信息
     *
     * @param taskExecutionRecord 采集任务执行记录信息
     * @return 结果
     */
    @Override
    public int updateTaskExecutionRecord(TaskExecutionRecord taskExecutionRecord)
    {
        return taskExecutionRecordMapper.updateTaskExecutionRecord(taskExecutionRecord);
    }

    /**
     * 批量删除采集任务执行记录信息
     *
     * @param recordIds 需要删除的采集任务执行记录信息主键
     * @return 结果
     */
    @Override
    public int deleteTaskExecutionRecordByRecordIds(String recordIds)
    {
        return taskExecutionRecordMapper.deleteTaskExecutionRecordByRecordIds(Convert.toStrArray(recordIds));
    }

    /**
     * 删除采集任务执行记录信息信息
     *
     * @param recordId 采集任务执行记录信息主键
     * @return 结果
     */
    @Override
    public int deleteTaskExecutionRecordByRecordId(Long recordId)
    {
        return taskExecutionRecordMapper.deleteTaskExecutionRecordByRecordId(recordId);
    }
}
